/*
 *    Copyright (c) 2018-2025, cloud All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: cloud
 */

package com.fuyao.cloud.asset.publicbarcode.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.asset.dto.barcode.AssetPublicbarcodeDTO;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.data.mybatis.SpliceQueryWrapper;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.asset.entity.AssetPublicbarcode;
import com.fuyao.cloud.asset.publicbarcode.service.AssetPublicbarcodeService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.fuyao.cloud.asset.vo.FyAssetPublicbarcodeExcelVO;

import java.util.List;

/**
 * 条码库
 *
 * @author 时间的朋友
 * @date 2021-11-17 14:47:09
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/fyassetpublicbarcode")
@Api(value = "fyassetpublicbarcode", tags = "条码库管理")
public class AssetPublicbarcodeController {

    private final AssetPublicbarcodeService fyAssetPublicbarcodeService;

    /**
     * 分页查询
     *
     * @param page                  分页对象
     * @param assetPublicbarcodeDTO 条码库
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('publicbarcode_fyassetpublicbarcode_view')")
    public R getFyAssetPublicbarcodePage(Page page, AssetPublicbarcodeDTO assetPublicbarcodeDTO) {
        return R.ok(fyAssetPublicbarcodeService.page(page, SpliceQueryWrapper.spliceSearchCondition(assetPublicbarcodeDTO)));
    }


    /**
     * 通过id查询条码库
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('publicbarcode_fyassetpublicbarcode_view')")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(fyAssetPublicbarcodeService.getById(id));
    }

    /**
     * 新增条码库
     *
     * @param fyAssetPublicbarcode 条码库
     * @return R
     */
    @ApiOperation(value = "新增条码库", notes = "新增条码库")
    @SysLog("新增条码库")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('publicbarcode_fyassetpublicbarcode_add')")
    public R save(@RequestBody AssetPublicbarcode fyAssetPublicbarcode) {
        fyAssetPublicbarcodeService.save(fyAssetPublicbarcode);
        return R.ok(fyAssetPublicbarcode, "保存成功");
    }

    /**
     * 修改条码库
     *
     * @param fyAssetPublicbarcode 条码库
     * @return R
     */
    @ApiOperation(value = "修改条码库", notes = "修改条码库")
    @SysLog("修改条码库")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('publicbarcode_fyassetpublicbarcode_edit')")
    public R updateById(@RequestBody AssetPublicbarcode fyAssetPublicbarcode) {
        return R.ok(fyAssetPublicbarcodeService.updateById(fyAssetPublicbarcode));
    }

    /**
     * 通过id删除条码库
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除条码库", notes = "通过id删除条码库")
    @SysLog("通过id删除条码库")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('publicbarcode_fyassetpublicbarcode_del')")
    public R removeById(@PathVariable Long id) {
        return R.ok(fyAssetPublicbarcodeService.removeById(id));
    }


    @ApiOperation(value = "批量删除条码库", notes = "批量删除条码库")
    @SysLog("批量删除条码库")
    @DeleteMapping("/batchDelete")
    @PreAuthorize("@pms.hasPermission('publicbarcode_fyassetpublicbarcode_del')")
    public R batchDelete(@RequestBody List<Long> ids) {
        return R.ok(fyAssetPublicbarcodeService.removeByIds(ids), String.format("成功删除%s条数据", ids.size()));
    }

    /**
     * 导出excel 表格
     *
     * @param assetPublicbarcodeDTO 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('publicbarcode_fyassetpublicbarcode_export')")
    public List<FyAssetPublicbarcodeExcelVO> export(AssetPublicbarcodeDTO assetPublicbarcodeDTO) {
        return fyAssetPublicbarcodeService.listExcel(SpliceQueryWrapper.spliceSearchCondition(assetPublicbarcodeDTO));
    }
}
